/** 
  成绩录入表
*/
<template>
  <div class="score-entry-table-container">
    <div class="blank-title">
      <span>{{ $t('scoreEntryMana.tjCollege') }}{{ basicInfo.calendarName }}{{ $t('scoreEntryMana.scoreRegistForm') }}</span>
      <el-dropdown @command="operateTable" style="float: right">
        <el-button>
          {{ $t('scoreMangementBase.import') }}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <!-- 导入 -->
          <el-dropdown-item command="1">
            <el-upload
              ref="importInfo"
              class="upload-demo"
              action="/dev/minorScoreEntryController/importMinorFinalStudentScoreInfo"
              :data="uploadConfig"
              :show-file-list="false"
              :on-success="(response, file, fileList) => handlerUploadSuccess(response, file, fileList)">
              <el-button type="text">{{ $t('scoreMangementBase.import') }}</el-button>
            </el-upload>
          </el-dropdown-item>
          <!-- 下载模板 -->
          <el-dropdown-item command="2">{{ $t('scoreMangementBase.downloadTemplate') }}</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <el-row class="blank-sub-title">
      <!-- 课程代码 -->
      <el-col :span="8">
        {{ $t('scoreEntryMana.courseCode') }}：{{ basicInfo.courseCode }}
      </el-col>
      <!-- 课程名称 -->
      <el-col :span="8">
        {{ $t('scoreEntryMana.courseName') }}：{{ basicInfo.courseName }}
      </el-col>
      <!-- 课程类别 -->
      <el-col :span="8">
        {{ $t('scoreEntryMana.courseType') }}：{{ basicInfo.courseLabel }}
      </el-col>
    </el-row>
    <el-row class="blank-sub-title">
      <!-- 课程序号 -->
      <el-col :span="8">
        {{ $t('scoreEntryMana.courseNum') }}：{{ basicInfo.courseNo }}
      </el-col>
      <!-- 开课学院 -->
      <el-col :span="8">
        {{ $t('scoreEntrySwitch.startCollege') }}：{{ basicInfo.faculty }}
      </el-col>
      <!-- 教师 -->
      <el-col :span="8">
        {{ $t('scoreEntryMana.tearcher') }}：{{ basicInfo.teacherCode }}{{ basicInfo.teacher }}
      </el-col>
    </el-row>
    <el-row class="blank-sub-title">
      <!-- 所录成绩 -->
      <el-col :span="16">
        {{ $t('scoreEntryMana.recordScore') }}：
        <template v-if="detailInfo.condition.examType === '2'">
          {{ basicInfo.scoreStructure }}
        </template>
        <template v-if="detailInfo.condition.examType === '1'">
          {{ $t('redelayTestScoreMana.redelayScore') }}
        </template>
      </el-col>
      <!-- （2分钟自动保存） -->
      <el-col :span="8">
        {{ $t('scoreEntryMana.admitPartialRelease') }}：{{ timeInfo.hour }}:{{ timeInfo.minute }}:{{ timeInfo.second }}
      </el-col>
    </el-row>
    <el-row style="margin: 15px 0;">
      <el-col :span="24">
        <el-form :model="dialogForm" label-position="right" ref="dialogForm" :inline="true">
          <el-table border stripe :data="dialogForm.dataList" size="mini">
            <!-- 序号 -->
            <el-table-column :label="$t('scoreEntryMana.serialNumber')" align="center">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <!-- 学号 -->
            <el-table-column :label="$t('scoreMangementBase.studentId')" prop="studentId" align="center"></el-table-column>
            <!-- 姓名 -->
            <el-table-column :label="$t('scoreMangementBase.studentName')" prop="studentName" align="center"></el-table-column>
            <!-- 修读类别 -->
            <el-table-column :label="$t('scoreEntryMana.courseCategory')" prop="learnType" align="center"></el-table-column>
            <!-- 平时成绩1 改为 过程性考核1 -->
            <el-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containDailyScore1" :label="$t('scoreEntryMana.usuallyOneGrade')" prop="dailyScore1" align="center" width="200">
              <template slot-scope="scope">
                <!-- 成绩记录方式开始 -->
                <el-form-item
                  :prop="'dataList.' + scope.$index + '.dailyScore1'" 
                  label-width="0"
                  :rules="basicInfo.minorScoreStructure.dailyScore1RecordType === '1001' ? 
                  isNaN(scope.row.dailyScore1) ? [] : [
                    { validator: validateScore, trigger: 'blur'}
                  ] : []">
                    <!-- 百分制 -->
                    <el-input v-if="basicInfo.minorScoreStructure.dailyScore1RecordType === '1001'" 
                      class="input" 
                      v-model.trim="scope.row.dailyScore1" 
                      :disabled="scope.row.disabledDailyScore1 || scope.row.dailyScore1ReleaseStatus === 1" 
                      :maxlength="5"
                      clearable
                      :placeholder="$t('common.pla.pleaseInput')"
                      @change="getLastScore(scope.row, scope.$index)">
                    </el-input>
                    <!-- 非百分制 -->
                    <el-select v-else class="select" v-model="scope.row.dailyScore1" @change="getLastScore(scope.row, scope.$index)" :disabled="scope.row.disabledDailyScore1 || scope.row.dailyScore1ReleaseStatus === 1" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <!-- 五级制 -->
                      <div v-show="basicInfo.minorScoreStructure.dailyScore1RecordType === '1002'">
                        <el-option
                          v-for="item in options.fiveLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                      <!-- 两级制 -->
                      <div v-show="basicInfo.minorScoreStructure.dailyScore1RecordType === '1003'">
                        <el-option
                          v-for="item in options.twoLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                    </el-select>
                    <!-- 百分制 -->
                  </el-form-item>
                  <!-- 成绩记录方式结束 -->
                  <!-- 考试性质开始 -->
                  <el-form-item
                  :prop="'dataList.' + scope.$index + '.dailyScore1examNature'" 
                  label-width="0">
                  <el-select class="select" v-model="scope.row.dailyScore1examNature" :disabled="scope.row.disabledScore1examNature || scope.row.dailyScore1ReleaseStatus === 1"  @change="(value) => changeExamNature(value, scope.$index, scope.row, 'dailyScore1examNature')" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                    <el-option
                      v-for="item in options.notFinalGradeList"
                      :key="item.key"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                  </el-form-item>
                  <!-- 考试性质结束 -->
              </template>
            </el-table-column>
            <!-- 平时成绩2 改为 过程性考核2 -->
            <el-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containDailyScore2" :label="$t('scoreEntryMana.usuallyTwoScore')" prop="" align="center" width="200">
              <template slot-scope="scope">
                <!-- 成绩记录方式开始 -->
                <el-form-item
                  :prop="'dataList.' + scope.$index + '.dailyScore2'" 
                  label-width="0"
                  :rules="basicInfo.minorScoreStructure.dailyScore2RecordType === '1001' ? 
                  isNaN(scope.row.dailyScore2) ? [] : [
                    { validator: validateScore, trigger: 'blur'}
                  ] : []">
                    <!-- 百分制 -->
                    <el-input v-if="basicInfo.minorScoreStructure.dailyScore2RecordType === '1001'" 
                      class="input" 
                      v-model.trim="scope.row.dailyScore2" 
                      :disabled="scope.row.disabledDailyScore2 || scope.row.dailyScore2ReleaseStatus === 1" 
                      :maxlength="5" 
                      clearable 
                      :placeholder="$t('common.pla.pleaseInput')"
                      @change="getLastScore(scope.row, scope.$index)">
                    </el-input>
                    <el-select v-else class="select" v-model="scope.row.dailyScore2" @change="getLastScore(scope.row, scope.$index)" :disabled="scope.row.disabledDailyScore2 || scope.row.dailyScore2ReleaseStatus === 1" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <!-- 五级制 -->
                      <div v-show="basicInfo.minorScoreStructure.dailyScore2RecordType === '1002'">
                        <el-option
                          v-for="item in options.fiveLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                      <!-- 两级制 -->
                      <div v-show="basicInfo.minorScoreStructure.dailyScore2RecordType === '1003'">
                        <el-option
                          v-for="item in options.twoLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                    </el-select>
                    <!-- 百分制 -->
                  </el-form-item>
                  <!-- 成绩记录方式结束 -->
                  <!-- 考试性质开始 -->
                  <el-form-item
                  :prop="'dataList.' + scope.$index + '.dailyScore2examNature'" 
                  label-width="0">
                  <el-select class="select" v-model="scope.row.dailyScore2examNature" :disabled="scope.row.disabledScore2examNature || scope.row.dailyScore2ReleaseStatus === 1" @change="(value) => changeExamNature(value, scope.$index, scope.row, 'dailyScore2examNature')" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                    <el-option
                      v-for="item in options.notFinalGradeList"
                      :key="item.key"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                  </el-form-item>
                  <!-- 考试性质结束 -->
              </template>
            </el-table-column>
            <!-- 期中成绩 改为 考勤 -->
            <el-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containMidtermScore" :label="$t('scoreEntryMana.midTermGrades')" prop="" align="center" width="200">
              <template slot-scope="scope">
                <!-- 成绩记录方式开始 -->
                <el-form-item
                  :prop="'dataList.' + scope.$index + '.midtermScore'" 
                  label-width="0"
                  :rules="basicInfo.minorScoreStructure.midtermScoreRecordType === '1001' ? 
                  isNaN(scope.row.midtermScore) ? [] : [
                    { validator: validateScore, trigger: 'blur'}
                  ] : []">
                    <!-- 百分制 -->
                    <el-input v-if="basicInfo.minorScoreStructure.midtermScoreRecordType === '1001'" 
                      class="input" 
                      v-model.trim="scope.row.midtermScore" 
                      :disabled="scope.row.disabledMidtermScore || scope.row.midtermScoreReleaseStatus === 1" 
                      :maxlength="5" 
                      clearable 
                      :placeholder="$t('common.pla.pleaseInput')"
                      @change="getLastScore(scope.row, scope.$index)">
                    </el-input>
                    <el-select v-else class="select" v-model="scope.row.midtermScore" @change="getLastScore(scope.row, scope.$index)" :disabled="scope.row.disabledMidtermScore || scope.row.midtermScoreReleaseStatus === 1" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <!-- 五级制 -->
                      <div v-show="basicInfo.minorScoreStructure.midtermScoreRecordType === '1002'">
                        <el-option
                          v-for="item in options.fiveLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                      <!-- 两级制 -->
                      <div v-show="basicInfo.minorScoreStructure.midtermScoreRecordType === '1003'">
                        <el-option
                          v-for="item in options.twoLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                    </el-select>
                    <!-- 百分制 -->
                  </el-form-item>
                  <!-- 成绩记录方式结束 -->
                  <!-- 考试性质开始 -->
                  <el-form-item
                  :prop="'dataList.' + scope.$index + '.midtermScoreexamNature'" 
                  label-width="0">
                    <el-select class="select" v-model="scope.row.midtermScoreexamNature" :disabled="scope.row.disabledMidtermScoreexamNature || scope.row.midtermScoreReleaseStatus === 1" @change="(value) => changeExamNature(value, scope.$index, scope.row, 'midtermScoreexamNature')" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <el-option
                        v-for="item in options.notFinalGradeList"
                        :key="item.key"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <!-- 考试性质结束 -->
              </template>
            </el-table-column>
            <!-- 期末成绩 -->
            <el-table-column v-if="detailInfo.condition.examType === '2'" :label="$t('scoreEntryMana.finalGrade')" prop="" align="center" width="200">
              <template slot-scope="scope">
                <!-- 成绩记录方式开始 -->
                <el-form-item
                  :prop="'dataList.' + scope.$index + '.finalScore'" 
                  label-width="0"
                  :rules="basicInfo.minorScoreStructure.finalScoreRecordType === '1001' ? 
                  isNaN(scope.row.finalScore) ? [] : [
                    { validator: validateScore, trigger: 'blur'}
                  ] : []">
                    <!-- 百分制 -->
                    <el-input v-if="basicInfo.minorScoreStructure.finalScoreRecordType === '1001'" 
                      class="input" 
                      v-model.trim="scope.row.finalScore" 
                      :disabled="scope.row.disabledFinalScore || scope.row.finalScoreReleaseStatus === 1 || scope.row.examSituation === '14002' || scope.row.examSituation === '14003'" 
                      :maxlength="5" 
                      clearable 
                      :placeholder="$t('common.pla.pleaseInput')"
                      @change="getLastScore(scope.row, scope.$index)">
                    </el-input>
                    <el-select v-else class="select" v-model="scope.row.finalScore" @change="getLastScore(scope.row, scope.$index)" :disabled="scope.row.disabledFinalScore || scope.row.finalScoreReleaseStatus === 1 || scope.row.examSituation === '14002' || scope.row.examSituation === '14003'" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <!-- 五级制 -->
                      <div v-show="basicInfo.minorScoreStructure.finalScoreRecordType === '1002'">
                        <el-option
                          v-for="item in options.fiveLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                      <!-- 两级制 -->
                      <div v-show="basicInfo.minorScoreStructure.finalScoreRecordType === '1003'">
                        <el-option
                          v-for="item in options.twoLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                    </el-select>
                    <!-- 百分制 -->
                  </el-form-item>
                  <!-- 成绩记录方式结束 -->
                  <!-- 考试性质开始 -->
                  <el-form-item
                  :prop="'dataList.' + scope.$index + '.finalScoreexamNature'" 
                  label-width="0">
                    <el-select class="select" v-model="scope.row.finalScoreexamNature" :disabled="scope.row.disabledFinalScoreexamNature || scope.row.finalScoreReleaseStatus === 1 || scope.row.examSituation === '14003'" @change="(value) => changeExamNature(value, scope.$index, scope.row, 'finalScoreexamNature')" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                     <div v-show="scope.row.examSituation !== '14002'">
                        <el-option
                          v-for="item in options.examNature"
                          :key="item.key"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                     </div>
                     <div v-show="scope.row.examSituation === '14002'">
                        <el-option
                          v-for="item in options.postponementOfExamination"
                          :key="item.key"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                     </div>
                    </el-select>
                  </el-form-item>
                <!-- 考试性质结束 -->
              </template>
            </el-table-column>
            <!-- 总评成绩 -->
            <el-table-column v-if="detailInfo.condition.examType === '2'" :label="$t('scoreEntryMana.overallRating')" prop="totalEvalScore" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.totalEvalScore }}</span>
              </template>
            </el-table-column>
            <!-- 重考成绩 -->
            <el-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containRetakeScore" :label="$t('redelayTestScoreMana.retakeScore')" prop="dailyScore1" align="center" width="200">
              <template slot-scope="scope">
                <!-- 成绩记录方式开始 -->
                <el-form-item
                  :prop="'dataList.' + scope.$index + '.retakeScore'" 
                  label-width="0"
                  :rules="basicInfo.minorScoreStructure.retakeScoreRecordType === '1001' ? [
                    { validator: validateScore, trigger: 'blur'}
                  ] : []">
                    <!-- 百分制 -->
                    <el-input v-if="basicInfo.minorScoreStructure.retakeScoreRecordType === '1001'" 
                      class="input" 
                      v-model.trim="scope.row.retakeScore" 
                      :disabled="scope.row.disableRetakeScore || scope.row.retakeScoreReleaseStatus === 1" 
                      :maxlength="5"
                      clearable
                      :placeholder="$t('common.pla.pleaseInput')"
                      @change="getLastScore(scope.row, scope.$index)">
                    </el-input>
                    <!-- 非百分制 -->
                    <el-select v-else class="select" v-model="scope.row.retakeScore" @change="getLastScore(scope.row, scope.$index)" :disabled="scope.row.disabledRetakeScore || scope.row.retakeScoreReleaseStatus === 1" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <!-- 五级制 -->
                      <div v-show="basicInfo.minorScoreStructure.retakeScoreRecordType === '1002'">
                        <el-option
                          v-for="item in options.fiveLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                      <!-- 两级制 -->
                      <div v-show="basicInfo.minorScoreStructure.retakeScoreRecordType === '1003'">
                        <el-option
                          v-for="item in options.twoLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                    </el-select>
                    <!-- 百分制 -->
                  </el-form-item>
                  <!-- 成绩记录方式结束 -->
                  <!-- 考试性质开始 -->
                  <el-form-item
                  :prop="'dataList.' + scope.$index + '.retakeScoreexamNature'" 
                  label-width="0">
                  <el-select class="select" v-model="scope.row.retakeScoreexamNature" :disabled="scope.row.disabledRetakeScoreexamNature || scope.row.retakeScoreReleaseStatus === 1"  @change="(value) => changeExamNature(value, scope.$index, scope.row, 'retakeScoreexamNature')" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                    <el-option
                      v-for="item in options.retakeExamList"
                      :key="item.key"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                  </el-form-item>
                  <!-- 考试性质结束 -->
              </template>
            </el-table-column>
            <!-- 缓考成绩 -->
            <el-table-column v-if="basicInfo.minorScoreStructureBean && basicInfo.minorScoreStructureBean.containSlowScore" :label="$t('redelayTestScoreMana.postponement')" prop="" align="center" width="200">
              <template slot-scope="scope">
                <!-- 成绩记录方式开始 -->
                <el-form-item
                  :prop="'dataList.' + scope.$index + '.slowScore'" 
                  label-width="0"
                  :rules="basicInfo.minorScoreStructure.slowScoreRecordType === '1001' ? [
                    { validator: validateScore, trigger: 'blur'}
                  ] : []">
                    <!-- 百分制 -->
                    <el-input v-if="basicInfo.minorScoreStructure.slowScoreRecordType === '1001'" 
                      class="input" 
                      v-model.trim="scope.row.slowScore" 
                      :disabled="scope.row.disabledDailyScore2 || scope.row.slowScoreReleaseStatus === 1" 
                      :maxlength="5" 
                      clearable 
                      :placeholder="$t('common.pla.pleaseInput')"
                      @change="getLastScore(scope.row, scope.$index)">
                    </el-input>
                    <el-select v-else class="select" v-model="scope.row.slowScore" @change="getLastScore(scope.row, scope.$index)" :disabled="scope.row.disabledSlowScore || scope.row.slowScoreReleaseStatus === 1" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                      <!-- 五级制 -->
                      <div v-show="basicInfo.minorScoreStructure.slowScoreRecordType === '1002'">
                        <el-option
                          v-for="item in options.fiveLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                      <!-- 两级制 -->
                      <div v-show="basicInfo.minorScoreStructure.slowScoreRecordType === '1003'">
                        <el-option
                          v-for="item in options.twoLevelList"
                          :key="item.gradeSetDetailsId"
                          :label="item.scoreName"
                          :value="item.gradeSetDetailsId">
                        </el-option>
                      </div>
                    </el-select>
                    <!-- 百分制 -->
                  </el-form-item>
                  <!-- 成绩记录方式结束 -->
                  <!-- 考试性质开始 -->
                  <el-form-item
                  :prop="'dataList.' + scope.$index + '.slowScoreexamNature'" 
                  label-width="0">
                  <el-select class="select" v-model="scope.row.slowScoreexamNature" :disabled="scope.row.disabledSlowScoreexamNature || scope.row.slowScoreReleaseStatus === 1" @change="(value) => changeExamNature(value, scope.$index, scope.row, 'slowScoreexamNature')" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                    <el-option
                      v-for="item in options.retakeExamList"
                      :key="item.key"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                  </el-form-item>
                  <!-- 考试性质结束 -->
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <div class="float-right" style="text-align: right;">
        <el-radio v-if="dialogForm.dataList.length > 0" v-model="dialogForm.releaseStatus" label="0">{{ $t('scoreEntryMana.immediateRelease') }}</el-radio>
        <el-radio v-if="dialogForm.dataList.length > 0" v-model="dialogForm.releaseStatus" style="margin-right: 0;" label="1">{{ $t('scoreEntryMana.timedRelease') }}</el-radio>
        <el-date-picker
          v-if="dialogForm.releaseStatus === '1' && dialogForm.dataList.length > 0"
          v-model="dialogForm.timedReleaseTime"
          type="datetime"
          format="yyyy/MM/dd HH:mm"
          :picker-options="pickerOptions0"
          :placeholder="$t('scoreMangementBase.chooseDateAndTime')">
        </el-date-picker>
        <div style="height: 50px;padding-top: 20px;">
          <el-button @click="prevStep()">{{ $t('scoreMangementBase.prevStrp') }}</el-button>
          <el-button v-if="dialogForm.dataList.length > 0" @click="save()">{{ $t('scoreMangementBase.save') }}</el-button>
          <el-button v-if="dialogForm.dataList.length > 0" @click="submitAndPublish()" type="primary">{{ $t('scoreMangementBase.submitAndPublish') }}</el-button>
        </div>
      </div>
    </el-row>
  </div>
</template>
<script>
import scoreManagementApi from 'common/src/api/scoreManagement/scoreManagement';
import UTILS from "common/src/utils/utils";
import { queryDic } from "common/src/api/dictionary";
import baseUrl from 'common/src/api/scoreManagement/env';
export default {
  components: {

  },
  data () {
    return {
      timeInfo: {
        hour: '00',
        minute: '02',
        second: '00'
      },
      timer: null,
      count: 120,
      options: {
        notFinalGradeList: [],
        retakeExamList: [],
        examNature: [],
        twoLevelList: [],
        fiveLevelList: [],
        hundredLevelList: [],
        allLevelList: [],
        postponementOfExamination: [] // 缓考：缓考+无资格
      },
      basicInfo: {},
      dialogForm: {
        dataList: [],
        releaseStatus: '0',
        timedReleaseTime: ''
      },
      totalGradeRecordInfo: {},
      // 考试性质字典
      examNatureObj: {},
      uploadConfig: {
        teachingClassId: '',
        calendarId: '',
        examType: '',
        courseCode: ''
      },
      dialogVisible: false,
      importForm: {
        importFile: ''
      },
      admitToPartlyRelease: false,
      pickerOptions0: {
	         disabledDate(time) {
	          //8.64e7
	          return time.getTime() < Date.now() - 8.64e7; //只能选择今天及今天之后
	          //return time.getTime() > Date.now() - 8.64e7; //只能选择今天之前，连今天都不能选
	          //return time.getTime() < Date.now() - 8.64e6; //只能选择今天之后，连今天都不能选
	          //return time.getTime() > Date.now() - 8.64e6; //只能选择今天及今天之前
	         }
	     }
    }
  },
  async mounted() {
    let _this = this
    await this.initOptions()
    await this.getGradeRecordMethod()
    scoreManagementApi.getFinalScoreEntryInitPage(this.detailInfo.condition).then(res => {
      if (res.code === 200 && res.data) {
        this.basicInfo = res.data
        this.dialogForm.dataList = this.basicInfo.studentList
        this.uploadConfig.teachingClassId = this.basicInfo.teachingClassId
        this.uploadConfig.calendarId = this.basicInfo.calendarId
        this.uploadConfig.examType = this.detailInfo.condition.examType
        this.uploadConfig.courseCode = this.basicInfo.courseCode
        this.dialogForm.dataList.map((value, index) => {
          // 成绩
          this.$set(value, 'dailyScore1', '')
          this.$set(value, 'dailyScore2', '')
          this.$set(value, 'midtermScore', '')
          this.$set(value, 'finalScore', '')
          this.$set(value, 'totalEvalScore', '')
          this.$set(value, 'retakeScore', '')
          this.$set(value, 'slowScore', '')
          // 禁止修改成绩
          this.$set(value, 'disabledDailyScore1', false)
          this.$set(value, 'disabledDailyScore2', false)
          this.$set(value, 'disabledMidtermScore', false)
          this.$set(value, 'disabledFinalScore', false)
          this.$set(value, 'disabledRetakeScore', value.examSituation === '14002')
          this.$set(value, 'disabledSlowScore', value.examSituation === '140021')
          // 禁止修改考试性质
          this.$set(value, 'disabledScore1examNature', false)
          this.$set(value, 'disabledScore2examNature', false)
          this.$set(value, 'disabledMidtermScoreexamNature', false)
          this.$set(value, 'disabledFinalScoreexamNature', false)
          this.$set(value, 'disabledRetakeScoreexamNature', value.examSituation === '14002')
          this.$set(value, 'disabledSlowScoreexamNature', value.examSituation === '140021')
          // 考试性质
          this.$set(value, 'dailyScore1examNature', '14001')
          this.$set(value, 'dailyScore2examNature', '14001')
          this.$set(value, 'midtermScoreexamNature', '14001')
          this.$set(value, 'retakeScoreexamNature', '14001')
          this.$set(value, 'slowScoreexamNature', '14001')
          // 发布状态
          this.$set(value, 'dailyScore1ReleaseStatus', null)
          this.$set(value, 'dailyScore2ReleaseStatus', null)
          this.$set(value, 'midtermScoreReleaseStatus', null)
          this.$set(value, 'retakeScoreReleaseStatus', null)
          this.$set(value, 'slowScoreReleaseStatus', null)
          this.$set(value, 'finalScoreReleaseStatus', null)
          this.$set(value, 'totalEvalScoreexamNature', '')
          // 考试类型为期末成绩,若申请了缓考,考试性质显示缓考,不可修改,否则选项显示全部,考试性质默认为正常
          if (this.basicInfo.minorScoreStructureBean.containFinalScore && value.examSituation === '14002') {
            this.$set(value, 'finalScoreexamNature', '14002')
            this.$set(this.dialogForm.dataList[index], 'finalScore', this.examNatureObj['14002'])
            this.$set(this.dialogForm.dataList[index], 'totalEvalScore', this.examNatureObj['14002'])
            this.$set(value, 'disabledFinalScore', true)
          } else if (this.basicInfo.minorScoreStructureBean.containFinalScore && value.examSituation === '14003') {
            this.$set(value, 'finalScoreexamNature', '14003')
            this.$set(this.dialogForm.dataList[index], 'finalScore', this.examNatureObj['14003'])
            this.$set(this.dialogForm.dataList[index], 'totalEvalScore', this.examNatureObj['14003'])
            this.$set(value, 'disabledFinalScore', true)
          } else {
            this.$set(value, 'finalScoreexamNature', '14001')
            this.$set(value, 'disabledFinalScore', false)
          }
        })
        this.dialogForm.dataList.forEach((stuValue, stuIndex, stuArr) => {
          if (stuValue.scoreDetails) {
            if (stuValue.scoreDetails.childBachelors.length > 0) {
              stuValue.scoreDetails.childBachelors.forEach((value, index, array) => {
                // 平时成绩1 改为 过程性考核1
                if (value.scoreType === '11005') {
                  this.$set(stuValue, 'dailyScore1', isNaN(value.score) ? value.score : (value.score !== '' ? Number(value.score) : ''))
                  this.$set(stuValue, 'dailyScore1examNature', value.scoreEaxmType.toString())
                  // 发布状态为已发布的不可修改成绩和考试性质
                  this.$set(stuValue, 'disabledDailyScore1', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'disabledScore1examNature', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'dailyScore1ReleaseStatus', value.releaseStatus)
                }
                // 平时成绩2 改为 过程性考核2
                if (value.scoreType === '11006') {
                  this.$set(stuValue, 'dailyScore2', isNaN(value.score) ? value.score : (value.score !== '' ? Number(value.score) : ''))
                  this.$set(stuValue, 'dailyScore2examNature', value.scoreEaxmType.toString())
                  // 发布状态为已发布的不可修改成绩和考试性质
                  this.$set(stuValue, 'disabledDailyScore2', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'disabledScore2examNature', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'dailyScore2ReleaseStatus', value.releaseStatus)
                }
                // 期中成绩 改为 考勤
                if (value.scoreType === '11007') {
                  this.$set(stuValue, 'midtermScore', isNaN(value.score) ? value.score : (value.score !== '' ? Number(value.score) : ''))
                  this.$set(stuValue, 'midtermScoreexamNature', value.scoreEaxmType.toString())
                  // 发布状态为已发布的不可修改成绩和考试性质
                  this.$set(stuValue, 'disabledMidtermScore', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'disabledMidtermScoreexamNature', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'midtermScoreReleaseStatus', value.releaseStatus)
                }
                // 期末成绩
                if (value.scoreType === '11008') {
                  this.$set(stuValue, 'finalScore', isNaN(value.score) ? value.score : (value.score !== '' ? Number(value.score) : ''))
                  // 当该学生的期末成绩为“免试”时，考试性质暂时设置为正常
                  if (value.scoreEaxmType === 140011) {
                    this.$set(stuValue, 'finalScoreexamNature', '14001')
                  } else {
                    this.$set(stuValue, 'finalScoreexamNature', value.scoreEaxmType.toString())
                  }
                  // 发布状态为已发布的不可修改成绩和考试性质
                  this.$set(stuValue, 'disabledFinalScore', stuValue.scoreDetails.releaseType === 1 || stuValue.scoreDetails.childBachelors[index].scoreEaxmType !== 14001)
                  this.$set(stuValue, 'disabledFinalScoreexamNature', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'finalScoreReleaseStatus', value.releaseStatus)
                }
                // 总评成绩
                if (value.scoreType === '11001') {
                  this.$set(stuValue, 'totalEvalScore', value.scoreValue)
                  this.$set(stuValue, 'totalEvalScoreexamNature', value.scoreEaxmType.toString())
                }
                // 重考成绩
                if (value.scoreType === '11004') {
                  this.$set(stuValue, 'retakeScore', isNaN(value.score) ? value.score : (value.score !== '' ? Number(value.score) : ''))
                  this.$set(stuValue, 'retakeScoreexamNature', value.scoreEaxmType.toString())
                  // 发布状态为已发布的不可修改成绩和考试性质
                  this.$set(stuValue, 'disabledRetakeScore', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'disabledRetakeScoreexamNature', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'retakeScoreReleaseStatus', value.releaseStatus)
                  // 排考的学生应考考试性质为缓考即限制填入重考信息
                  if (stuValue.examSituation === '14002') {
                    this.$set(stuValue, 'disabledRetakeScore', true)
                    this.$set(stuValue, 'disabledRetakeScoreexamNature', true)
                  }
                }
                // 缓考成绩
                if (value.scoreType === '11003') {
                  this.$set(stuValue, 'slowScore', isNaN(value.score) ? value.score : (value.score !== '' ? Number(value.score) : ''))
                  this.$set(stuValue, 'slowScoreexamNature', value.scoreEaxmType.toString())
                  // 发布状态为已发布的不可修改成绩和考试性质
                  this.$set(stuValue, 'disabledSlowScore', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'disabledSlowScoreexamNature', stuValue.scoreDetails.releaseType === 1)
                  this.$set(stuValue, 'slowScoreReleaseStatus', value.releaseStatus)
                  // 排考的学生应考考试性质为重考即限制填入缓考信息
                  if (stuValue.examSituation === '140021') {
                    this.$set(stuValue, 'disabledSlowScore', true)
                    this.$set(stuValue, 'disabledSlowScoreexamNature', true)
                  }
                }
              })
            }
          }
        })
        // console.log(this.dialogForm.dataList)
        scoreManagementApi.getTotalEvalScoreRecordType({
          "calendarId": this.basicInfo.calendarId,
          "facultyIds": this.basicInfo.facultyCode
        }).then(resp => {
          if (resp.code === 200) {
            this.totalGradeRecordInfo = resp.data[0]
          }
        })
        this.getCanBePartlyRelease()
      }
    })
  },
  props: {
    detailInfo: {
      type: Object,
      default: () => {}
    }
  },
  filters: {
  },
  methods: {
    validateScore(rule, value, callback) {
      let expReg = /^(\d{1,3})?(\.\d{1})?$/
      if (Number(value) > 100) {
        callback(new Error(this.$t('gradeRelatedSetting.lessThanMax')))
      } else if (!expReg.test(value)) {
        callback(new Error(this.$t('gradeRelatedSetting.validateGradeShort')))
      } else {
        callback()
      }
    },
    async initOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: [
          "X_YXCK_FX" // 辅修允许重考的考试情况
        ]
      }
      let resp = await queryDic(data)
      if (resp.code === 200) {
        this.examNatureObj = resp.data["X_YXCK_FX"]
        UTILS.fillSelect(
          {
            examNature: "X_YXCK_FX" // 辅修允许重考的考试情况
          },
          resp.data,
          this.options
        )
        // 正常+违纪
        this.options.notFinalGradeList = this.options.examNature.filter(value => {
          return value.value === '14001' || value.value === '14004'
        })
        // 重缓考：正常+无资格+违纪+旷考
        this.options.retakeExamList = this.options.examNature.filter(value => {
          return value.value !== '14002'
        })
        // 缓考：缓考+无资格
        this.options.postponementOfExamination = this.options.examNature.filter(value => {
          return value.value === '14002' || value.value === '14003'
        })
      }
    },
    // 查询是否允许部分发布课程
    async getCanBePartlyRelease() {
      let resp = await scoreManagementApi.queryWhiteCourseInfoByCode({
        'courseCode': this.basicInfo.courseCode
      })
      if (resp.code === 200 && resp.data) {
        this.admitToPartlyRelease = true
        this.timer = setInterval(() => {
          this.getTime()
        }, 1000)
      } else {
        this.admitToPartlyRelease = false
      }
    },
    // 时间计时
    getTime() {
      if (this.count === 0) {
        this.save()
        this.count = 120
      }
      if (this.count > 0) {
        this.timeInfo.minute = '0' + Math.floor(this.count / 60)
        this.timeInfo.second = Math.floor(this.count % 60) < 10 ? ('0' + Math.floor(this.count % 60)) : Math.floor(this.count % 60)
        --this.count
      } else {
        clearInterval(this.timer)
      }
    },
    // 返回主页
    backToMain() {
      this.$emit('refresh-main-page')
    },
    // 导入/下载模板
    operateTable(type) {
      if (type === '2') {
        window.open(baseUrl + "/minorScoreEntryController/downloadMinorFinalStudentScoreTemplate?calendarId=" + this.basicInfo.calendarId + '&examType=' + this.detailInfo.condition.examType + '&teachingClassId=' + this.basicInfo.teachingClassId + '&courseCode=' + this.basicInfo.courseCode)
      }
    },
    // 获取成绩记录方式
    async getGradeRecordMethod() {
      let resp = await scoreManagementApi.getScoreRecordMethodList({
        "gradeNameCn": "",
        "pageNum_": 1,
        "pageSize_": 20
      })
      if (resp.code === 200) {
        if (resp.data.list.length > 0) {
          resp.data.list.forEach(value => {
            // 两级制
            if (value.gradeNameCode === '1003') {
              this.options.twoLevelList = value.minorGradeRelatedSetDetailsList
            } else if (value.gradeNameCode === '1002') { // 五级制
              this.options.fiveLevelList = value.minorGradeRelatedSetDetailsList
            } else if (value.gradeNameCode === '1001') { // 百分制
              this.options.hundredLevelList = value.minorGradeRelatedSetDetailsList
            }
          })
          // this.options.twoLevelList.map(value => {
          //   value.gradeSetDetailsId = String(value.gradeSetDetailsId)
          // })
          // this.options.fiveLevelList.map(value => {
          //   value.gradeSetDetailsId = String(value.gradeSetDetailsId)
          // })
          // this.options.hundredLevelList.map(value => {
          //   value.gradeSetDetailsId = String(value.gradeSetDetailsId)
          // })
          this.options.allLevelList = [].concat(this.options.twoLevelList, this.options.fiveLevelList, this.options.hundredLevelList)
        }
      }
    },
    // 获取导入的数据
    handlerUploadSuccess(response, file, fileList) {
      if (response.code === 200) {
        if (response.data.length && response.data.length > 0) {
          let respData = JSON.parse(JSON.stringify(response.data))
          let stuList = []
          if (respData.length > 0) {
            if (this.dialogForm.dataList.length > 0) {
              this.dialogForm.dataList.map((stuValue, stuIndex, stuArray) => {
                respData.map((value, index, array) => {
                  // 当前学生所有成绩均未发布（包含：1.所有成绩未发布；2.部分成绩发布，部分成绩未发布）
                  if (stuValue.studentId === value.studentId && ((stuValue.scoreDetails && stuValue.scoreDetails.releaseType !== 1) || !stuValue.scoreDetails)) {
                    if (value.childBachelors.length > 0) {
                      value.childBachelors.map((childValue, childIndex) => {
                        if (childValue.scoreEaxmType && childValue.score) {
                          // 平时成绩1 改为 过程性考核1
                          if (childValue.scoreType === '11005' && stuValue.dailyScore1ReleaseStatus !== 1) {
                            stuValue.dailyScore1examNature = childValue.scoreEaxmType ? childValue.scoreEaxmType.toString() : childValue.scoreEaxmType
                            stuValue.dailyScore1 = (stuValue.dailyScore1examNature && stuValue.dailyScore1examNature !== '14001') ? this.examNatureObj[stuValue.dailyScore1examNature] : childValue.score !== null ? Number(childValue.score) : ''
                            stuValue.disabledDailyScore1 = stuValue.dailyScore1examNature && stuValue.dailyScore1examNature !== '14001'
                          }
                          // 平时成绩2 改为 过程性考核2
                          if (childValue.scoreType === '11006' && stuValue.dailyScore2ReleaseStatus !== 1) {
                            stuValue.dailyScore2examNature = childValue.scoreEaxmType ? childValue.scoreEaxmType.toString() : childValue.scoreEaxmType
                            stuValue.dailyScore2 = (stuValue.dailyScore2examNature && stuValue.dailyScore2examNature !== '14001') ? this.examNatureObj[stuValue.dailyScore2examNature] : childValue.score !== null ? Number(childValue.score) : ''
                            stuValue.disabledDailyScore2 = stuValue.dailyScore2examNature && stuValue.dailyScore2examNature !== '14001'
                          }
                          // 期中成绩 改为 考勤
                          if (childValue.scoreType === '11007' && stuValue.midtermScoreReleaseStatus !== 1) {
                            stuValue.midtermScoreexamNature = childValue.scoreEaxmType ? childValue.scoreEaxmType.toString() : childValue.scoreEaxmType
                            stuValue.midtermScore = (stuValue.midtermScoreexamNature && stuValue.midtermScoreexamNature !== '14001') ? this.examNatureObj[stuValue.midtermScoreexamNature] : childValue.score !== null ? Number(childValue.score) : ''
                            stuValue.disabledMidtermScore = stuValue.midtermScoreexamNature && stuValue.midtermScoreexamNature !== '14001'
                          }
                          // 期末成绩
                          if (childValue.scoreType === '11008' && stuValue.finalScoreReleaseStatus !== 1 && ((stuValue.finalScoreexamNature === '14002' && (childValue.scoreEaxmType === 14002 || childValue.scoreEaxmType === 14003)) || (stuValue.finalScoreexamNature !== '14003' && stuValue.finalScoreexamNature !== '14002')) ) {
                            stuValue.finalScoreexamNature = childValue.scoreEaxmType ? childValue.scoreEaxmType.toString() : childValue.scoreEaxmType
                            stuValue.finalScore = (stuValue.finalScoreexamNature && stuValue.finalScoreexamNature !== '14001') ? this.examNatureObj[stuValue.finalScoreexamNature] : childValue.score !== null ? Number(childValue.score) : ''
                            stuValue.disabledFinalScore = stuValue.finalScoreexamNature && stuValue.finalScoreexamNature !== '14001'
                          }
                          // 重考成绩
                          if (childValue.scoreType === '11004' && stuValue.retakeScoreReleaseStatus !== 1) {
                            stuValue.retakeScoreexamNature = childValue.scoreEaxmType ? childValue.scoreEaxmType.toString() : childValue.scoreEaxmType
                            stuValue.retakeScore = (stuValue.retakeScoreexamNature && stuValue.retakeScoreexamNature !== '14001') ? this.examNatureObj[stuValue.retakeScoreexamNature] : childValue.score !== null ? Number(childValue.score) : ''
                            stuValue.disabledRetakeScore = stuValue.retakeScoreexamNature && stuValue.retakeScoreexamNature !== '14001'
                          }
                          // 缓考成绩
                          if (childValue.scoreType === '11003' && stuValue.slowScoreReleaseStatus !== 1) {
                            stuValue.slowScoreexamNature = childValue.scoreEaxmType ? childValue.scoreEaxmType.toString() : childValue.scoreEaxmType
                            stuValue.slowScore = (stuValue.slowScoreexamNature && stuValue.slowScoreexamNature !== '14001') ? this.examNatureObj[stuValue.slowScoreexamNature] : childValue.score !== null ? Number(childValue.score) : ''
                            stuValue.disabledSlowScore = stuValue.slowScoreexamNature && stuValue.slowScoreexamNature !== '14001'
                          }
                        }
                      })
                    }
                    this.getLastScore(stuValue, stuIndex)
                  }
                })
              })
            }
          }
        }
      } else {
        window.vueApp.showMsgBox({
          message: response.msg
        })
      }
    },
    // 修改考试性质
    changeExamNature(value, index, row, examNatureType) {
      // 平时成绩1 改为 过程性考核1
      if (examNatureType === 'dailyScore1examNature') {
        if (value === '14004') {
          this.$set(this.dialogForm.dataList[index], 'dailyScore1', this.examNatureObj['14004'])
          this.$set(this.dialogForm.dataList[index], 'disabledDailyScore1', true)
        } else {
          this.$set(this.dialogForm.dataList[index], 'dailyScore1', '')
          this.$set(this.dialogForm.dataList[index], 'disabledDailyScore1', false)
        }
      }
      // 平时成绩2 改为 过程性考核2
      if (examNatureType === 'dailyScore2examNature') {
        if (value === '14004') {
          this.$set(this.dialogForm.dataList[index], 'dailyScore2', this.examNatureObj['14004'])
          this.$set(this.dialogForm.dataList[index], 'disabledDailyScore2', true)
        } else {
          this.$set(this.dialogForm.dataList[index], 'dailyScore2', '')
          this.$set(this.dialogForm.dataList[index], 'disabledDailyScore2', false)
        }
      }
      // 期中成绩 改为 考勤
      if (examNatureType === 'midtermScoreexamNature') {
        if (value === '14004') {
          this.$set(this.dialogForm.dataList[index], 'midtermScore', this.examNatureObj['14004'])
          this.$set(this.dialogForm.dataList[index], 'disabledMidtermScore', true)
        } else {
          this.$set(this.dialogForm.dataList[index], 'midtermScore', '')
          this.$set(this.dialogForm.dataList[index], 'disabledMidtermScore', false)
        }
      }
      // 期末成绩
      if (examNatureType === 'finalScoreexamNature') {
        // 考试性质为正常
        if (value === '14001') {
          this.$set(this.dialogForm.dataList[index], 'finalScore', '')
          this.$set(this.dialogForm.dataList[index], 'disabledFinalScore', false)
        } else {
          this.$set(this.dialogForm.dataList[index], 'finalScore', this.examNatureObj[value])
          this.$set(this.dialogForm.dataList[index], 'disabledFinalScore', true)
        }
      }
      // 重考成绩
      if (examNatureType === 'retakeScoreexamNature') {
        // 考试性质为正常
        if (value === '14001') {
          this.$set(this.dialogForm.dataList[index], 'retakeScore', '')
          this.$set(this.dialogForm.dataList[index], 'disabledRetakeScore', false)
        } else {
          this.$set(this.dialogForm.dataList[index], 'retakeScore', this.examNatureObj[value])
          this.$set(this.dialogForm.dataList[index], 'disabledRetakeScore', true)
        }
      }
      // 缓考成绩
      if (examNatureType === 'slowScoreexamNature') {
        // 考试性质为正常
        if (value === '14001') {
          this.$set(this.dialogForm.dataList[index], 'slowScore', '')
          this.$set(this.dialogForm.dataList[index], 'disabledSlowScore', false)
        } else {
          this.$set(this.dialogForm.dataList[index], 'slowScore', this.examNatureObj[value])
          this.$set(this.dialogForm.dataList[index], 'disabledSlowScore', true)
        }
      }
      if (examNatureType !== 'retakeScoreexamNature' && examNatureType !== 'slowScoreexamNature') {
        // 如果考试性质为非正常,总评成绩即为非正常的考试性质,违纪>非正常
        this.getLastScore(row, index)
      }
    },
    // 动态计算总评成绩的显示
    getLastScore(row, index) {
      // 默认不存在违纪
      let breachOfDisciplineFlag = false
      // 若存在平时成绩1
      if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containDailyScore1) {
        // 考试性质存在违纪
        if (row.dailyScore1examNature === '14004') {
          breachOfDisciplineFlag = true
        }
      }
      // 若存在平时成绩2
      if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containDailyScore2) {
        // 考试性质存在违纪
        if (row.dailyScore2examNature === '14004') {
          breachOfDisciplineFlag = true
        }
      }
      // 若存在期中成绩
      if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containMidtermScore) {
        // 考试性质存在违纪
        if (row.midtermScoreexamNature === '14004') {
          breachOfDisciplineFlag = true
        }
      }
      // 若存在期末成绩
      if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containFinalScore) {
        // 考试性质存在违纪
        if (row.finalScoreexamNature === '14004') {
          breachOfDisciplineFlag = true
        }
      }
      // 若成绩构成的成绩类型的考试性质存在违纪,则总评成绩为违纪
      if (breachOfDisciplineFlag) {
        this.basicInfo.studentList[index]['totalEvalScore'] = UTILS.translateLabel(this.options.examNature, '14004', 'value', 'label')
      } else {
        // 判定是否包含期末成绩
        if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containFinalScore) {
          // 判定期末成绩的考试性质为"无资格/旷考/缓考",则总评成绩显示为"对应的中文"
          // 无资格
          if (row.finalScoreexamNature === '14003') {
            this.basicInfo.studentList[index]['totalEvalScore'] = UTILS.translateLabel(this.options.examNature, '14003', 'value', 'label')
          }
          // 旷考
          if (row.finalScoreexamNature === '14005') {
            this.basicInfo.studentList[index]['totalEvalScore'] = UTILS.translateLabel(this.options.examNature, '14005', 'value', 'label')
          }
          // 缓考
          if (row.finalScoreexamNature === '14002') {
            this.basicInfo.studentList[index]['totalEvalScore'] = UTILS.translateLabel(this.options.examNature, '14002', 'value', 'label')
          }
          // 期末成绩的考试性质不是"无资格/旷考/缓考",所有成绩考试性质都为"正常"
          // 判定是否存在某成绩类型成绩未录入
          let hasNotEntried = false
          // 包含平时成绩1
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containDailyScore1) {
            // 平时成绩1未录入
            if (!row.dailyScore1) {
              hasNotEntried = true
            }
          }
          // 包含平时成绩2
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containDailyScore2) {
            // 平时成绩2未录入
            if (!row.dailyScore2) {
              hasNotEntried = true
            }
          }
          // 包含期中成绩
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containMidtermScore) {
            // 期中成绩未录入
            if (!row.midtermScore) {
              hasNotEntried = true
            }
          }
          // 包含期末成绩
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containFinalScore) {
            // 期中成绩未录入
            if (!row.finalScore && row.finalScore !== 0) {
              hasNotEntried = true
            }
          }
          // 存在某成绩类型未录入
          if (hasNotEntried) {
            // this.basicInfo.studentList[index]['totalEvalScore'] = ''
            this.$set(this.dialogForm.dataList[index], 'totalEvalScore', '')
            return
          }
          // 所有成绩类型均已录入
          // 包含平时成绩1
          let totalGrade = 0
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containDailyScore1) {
            // 如果平时成绩1的成绩记录方式为两级制
            if (this.basicInfo.minorScoreStructure.dailyScore1RecordType === '1003') {
              totalGrade += this.getHundrendDefaultValue(row.dailyScore1, this.options.twoLevelList) * (this.basicInfo.minorScoreStructure.dailyScore1Proportion / 100)
            }
            // 如果平时成绩1的成绩记录方式为五级制
            if (this.basicInfo.minorScoreStructure.dailyScore1RecordType === '1002') {
              totalGrade += this.getHundrendDefaultValue(row.dailyScore1, this.options.fiveLevelList) * (this.basicInfo.minorScoreStructure.dailyScore1Proportion / 100)
            }
            // 如果平时成绩1的成绩记录方式为百分制
            if (this.basicInfo.minorScoreStructure.dailyScore1RecordType === '1001') {
              totalGrade += row.dailyScore1 * (this.basicInfo.minorScoreStructure.dailyScore1Proportion / 100)
            }
          }
          // 包含平时成绩2
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containDailyScore2) {
            // 如果平时成绩2的成绩记录方式为两级制
            if (this.basicInfo.minorScoreStructure.dailyScore2RecordType === '1003') {
              totalGrade += this.getHundrendDefaultValue(row.dailyScore2, this.options.twoLevelList) * (this.basicInfo.minorScoreStructure.dailyScore2Proportion / 100)
            }
            // 如果平时成绩2的成绩记录方式为五级制
            if (this.basicInfo.minorScoreStructure.dailyScore2RecordType === '1002') {
              totalGrade += this.getHundrendDefaultValue(row.dailyScore2, this.options.fiveLevelList) * (this.basicInfo.minorScoreStructure.dailyScore2Proportion / 100)
            }
            // 如果平时成绩2的成绩记录方式为百分制
            if (this.basicInfo.minorScoreStructure.dailyScore2RecordType === '1001') {
              totalGrade += row.dailyScore2 * (this.basicInfo.minorScoreStructure.dailyScore2Proportion / 100)
            }
          }
          // 包含期中成绩
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containMidtermScore) {
            // 如果期中成绩的成绩记录方式为两级制
            if (this.basicInfo.minorScoreStructure.midtermScoreRecordType === '1003') {
              totalGrade += this.getHundrendDefaultValue(row.midtermScore, this.options.twoLevelList) * (this.basicInfo.minorScoreStructure.midtermScoreProportion / 100)
            }
            // 如果期中成绩的成绩记录方式为五级制
            if (this.basicInfo.minorScoreStructure.midtermScoreRecordType === '1002') {
              totalGrade += this.getHundrendDefaultValue(row.midtermScore, this.options.fiveLevelList) * (this.basicInfo.minorScoreStructure.midtermScoreProportion / 100)
            }
            // 如果期中成绩的成绩记录方式为百分制
            if (this.basicInfo.minorScoreStructure.midtermScoreRecordType === '1001') {
              totalGrade += row.midtermScore * (this.basicInfo.minorScoreStructure.midtermScoreProportion / 100)
            }
          }
          // 包含期末成绩
          if (this.basicInfo.minorScoreStructureBean && this.basicInfo.minorScoreStructureBean.containFinalScore) {
            if (isNaN(row.finalScore)) {
              totalGrade = row.finalScore
            } else {
              // totalGrade += row.finalScore * (this.basicInfo.minorScoreStructure.finalScoreProportion / 100)
              // 如果期末成绩的成绩记录方式为两级制
              if (this.basicInfo.minorScoreStructure.finalScoreRecordType === '1003') {
                totalGrade += this.getHundrendDefaultValue(row.finalScore, this.options.twoLevelList) * (this.basicInfo.minorScoreStructure.finalScoreProportion / 100)
              }
              // 如果期末成绩的成绩记录方式为五级制
              if (this.basicInfo.minorScoreStructure.finalScoreRecordType === '1002') {
                totalGrade += this.getHundrendDefaultValue(row.finalScore, this.options.fiveLevelList) * (this.basicInfo.minorScoreStructure.finalScoreProportion / 100)
              }
              // 如果期末成绩的成绩记录方式为百分制
              if (this.basicInfo.minorScoreStructure.finalScoreRecordType === '1001') {
                totalGrade += row.finalScore * (this.basicInfo.minorScoreStructure.finalScoreProportion / 100)
              }
            }
          }
          // 判定总评成绩的成绩记录方式为两级制或者五级制
          if (this.totalGradeRecordInfo.totalInputType === '1002' || this.totalGradeRecordInfo.totalInputType === '1003') {
            totalGrade = isNaN(totalGrade) ? totalGrade : Math.round(totalGrade)
            // 两级制
            if (this.totalGradeRecordInfo.totalInputType === '1003') {
              this.options.twoLevelList.forEach((value, index) => {
                if (totalGrade >= value.scoreMin && totalGrade <= value.scoreMax) {
                  totalGrade = value.scoreName
                }
              })
            }
            // 五级制
            if (this.totalGradeRecordInfo.totalInputType === '1002') {
              this.options.fiveLevelList.forEach((value, index) => {
                if (totalGrade >= value.scoreMin && totalGrade <= value.scoreMax) {
                  totalGrade = value.scoreName
                }
              })
            }
            this.$set(this.dialogForm.dataList[index], 'totalEvalScore', totalGrade)
          }
          // 判定总评成绩的成绩记录方式为百分制
          if (this.totalGradeRecordInfo.totalInputType === '1001') {
            this.$set(this.dialogForm.dataList[index], 'totalEvalScore', isNaN(totalGrade) ? totalGrade : (Math.round(totalGrade * 100) / 100))
          }
        }
      }
    },
    // 获取两级制/五级制转换成百分制的默认值
    getHundrendDefaultValue(gradeSetDetailsId, minorGradeRelatedSetDetailsList) {
      let scoreDefault = 0
      minorGradeRelatedSetDetailsList.map(value => {
        if (value.gradeSetDetailsId === gradeSetDetailsId) {
          scoreDefault = value.scoreDefault
        }
      })
      return scoreDefault
    },
    // 返回
    back() {
      this.$emit('refresh-main-page')
    },
    // 上一步
    prevStep() {
      clearInterval(this.timer)
      this.$emit('get-prev-step')
    },
    // 保存数据
    saveData(operationType) {
      let params = []
      let hasBlankTotalScore = false
      let hasBlankRetakeOrSlow = false
      this.dialogForm.dataList.map((value, index, array) => {
        let currentObj = {
          calendarId: this.basicInfo.calendarId,
          teachingClassId: this.basicInfo.teachingClassId,
          courseCode: this.basicInfo.courseCode,
          studentId: value.studentId,
          studentName: value.studentName,
          courseNo: this.basicInfo.courseNo,
          courseName: this.basicInfo.courseName,
          factory: this.basicInfo.faculty,
          facultyCode: this.basicInfo.facultyCode,
          operationType: operationType,
          releaseType: operationType,
          releaseCronType: this.dialogForm.releaseStatus,
          releaseAt: this.dialogForm.timedReleaseTime ? new Date(this.dialogForm.timedReleaseTime).getTime() : this.dialogForm.timedReleaseTime,
          courseLabel: this.basicInfo.courseLabel,
          childBachelors: []
        }
        // 重缓考
        if (this.detailInfo.condition.examType === '1') {
          currentObj['keepField'] = '1'
        }
        // 期末总评
        if (this.detailInfo.condition.examType === '2') {
          currentObj['keepField'] = '2'
        }
        currentObj['originalCalendar'] = value.originalCalendar
        // 平时成绩1 改为 过程性考核1
        if (this.basicInfo.minorScoreStructureBean.containDailyScore1) {
          currentObj.childBachelors.push({
            "score": value.dailyScore1 ? value.dailyScore1.toString() : value.dailyScore1,
            "scoreValue": this.basicInfo.minorScoreStructure.dailyScore1RecordType === '1001' ? (value.dailyScore1 ? value.dailyScore1.toString() : value.dailyScore1) : (value.dailyScore1examNature !== '14001' ? value.dailyScore1 : UTILS.translateLabel(this.options.allLevelList, value.dailyScore1, 'gradeSetDetailsId', 'scoreName')),
            "scoreRecordType": this.basicInfo.minorScoreStructure.dailyScore1RecordType,
            "scoreEaxmType": value.dailyScore1examNature,
            "scoreType": "11005",
            "keepField": "2"
          })
        }
        // 平时成绩2 改为 过程性考核2
        if (this.basicInfo.minorScoreStructureBean.containDailyScore2) {
          currentObj.childBachelors.push({
            "score":  value.dailyScore2 ? value.dailyScore2.toString() : value.dailyScore2,
            "scoreValue": this.basicInfo.minorScoreStructure.dailyScore2RecordType === '1001' ? (value.dailyScore2 ? value.dailyScore2.toString() : value.dailyScore2) : (value.dailyScore2examNature !== '14001' ? value.dailyScore2 : UTILS.translateLabel(this.options.allLevelList, value.dailyScore2, 'gradeSetDetailsId', 'scoreName')),
            "scoreRecordType": this.basicInfo.minorScoreStructure.dailyScore2RecordType,
            "scoreEaxmType": value.dailyScore2examNature,
            "scoreType": "11006",
            "keepField": "2"
          })
        }
        // 期中考试 改为 考勤
        if (this.basicInfo.minorScoreStructureBean.containMidtermScore) {
          currentObj.childBachelors.push({
            "score": value.midtermScore ? value.midtermScore.toString() : value.midtermScore,
            "scoreValue": this.basicInfo.minorScoreStructure.midtermScoreRecordType === '1001' ? (value.midtermScore ? value.midtermScore.toString() : value.midtermScore) : (value.midtermScoreexamNature !== '14001' ? value.midtermScore : UTILS.translateLabel(this.options.allLevelList, value.midtermScore, 'gradeSetDetailsId', 'scoreName')),
            "scoreRecordType": this.basicInfo.minorScoreStructure.midtermScoreRecordType,
            "scoreEaxmType": value.midtermScoreexamNature,
            "scoreType": "11007",
            "keepField": "2"
          })
        }
        // 期末考试
        if (this.basicInfo.minorScoreStructureBean.containFinalScore) {
          currentObj.childBachelors.push({
            "score": value.finalScore ? value.finalScore.toString() : value.finalScore,
            "scoreValue": this.basicInfo.minorScoreStructure.finalScoreRecordType === '1001' ? (value.finalScore ? value.finalScore.toString() : value.finalScore) : (value.finalScoreexamNature !== '14001' ? value.finalScore : UTILS.translateLabel(this.options.allLevelList, value.finalScore, 'gradeSetDetailsId', 'scoreName')),
            "scoreRecordType": this.basicInfo.minorScoreStructure.finalScoreRecordType,
            "scoreEaxmType": value.finalScoreexamNature,
            "scoreType": "11008",
            "keepField": "2"
          })
        }

        // 重考成绩
        if (this.basicInfo.minorScoreStructureBean.containRetakeScore) {
          currentObj['examSituation'] = value.examSituation
          currentObj.childBachelors.push({
            "score": value.retakeScore ? value.retakeScore.toString() : value.retakeScore,
            "scoreValue": this.basicInfo.minorScoreStructure.retakeScoreRecordType === '1001' ? (value.retakeScore ? value.retakeScore.toString() : value.retakeScore) : (value.retakeScoreexamNature !== '14001' ? value.retakeScore : UTILS.translateLabel(this.options.allLevelList, value.retakeScore, 'gradeSetDetailsId', 'scoreName')),
            "scoreRecordType": this.basicInfo.minorScoreStructure.retakeScoreRecordType,
            "scoreEaxmType": value.retakeScoreexamNature,
            "scoreType": "11004",
            "keepField": "1"
          })
        }
        // 缓考成绩
        if (this.basicInfo.minorScoreStructureBean.containSlowScore) {
          currentObj['examSituation'] = value.examSituation
          currentObj.childBachelors.push({
            "score": value.slowScore ? value.slowScore.toString() : value.slowScore,
            "scoreValue": this.basicInfo.minorScoreStructure.slowScoreRecordType === '1001' ? (value.slowScore ? value.slowScore.toString() : value.slowScore) : (value.slowScoreexamNature !== '14001' ? value.slowScore : UTILS.translateLabel(this.options.allLevelList, value.slowScore, 'gradeSetDetailsId', 'scoreName')),
            "scoreRecordType": this.basicInfo.minorScoreStructure.slowScoreRecordType,
            "scoreEaxmType": value.slowScoreexamNature,
            "scoreType": "11003",
            "keepField": "1"
          })
        }
        // 期末总评
        if (this.detailInfo.condition.examType === '2') {
          // 总评成绩逻辑开始
          let totalScoreValue = array[index].totalEvalScore
          let totalScore = null
          // 考试性质
          let totalExamNature = null
          if (totalScoreValue !== this.examNatureObj['14001'] && Object.values(this.examNatureObj).includes(totalScoreValue)) {
            for (let key in this.examNatureObj) {
              if (totalScoreValue === this.examNatureObj[key]) {
                totalExamNature = key
              }
            }
          } else {
            totalExamNature = '14001'
          }
          // 若总评成绩为五级制
          if (this.totalGradeRecordInfo.totalInputType === '1002') {
            if (totalExamNature === '14001') {
              this.options.fiveLevelList.map(item => {
                if (item.scoreName === totalScoreValue) {
                  totalScore = item.gradeSetDetailsId
                }
              })
            } else {
              totalScore = totalScoreValue
            }
          }
          // 若总评成绩为两级制
          if (this.totalGradeRecordInfo.totalInputType === '1003') {
            if (totalExamNature === '14001') {
              this.options.twoLevelList.map(item => {
                if (item.scoreName === totalScoreValue) {
                  totalScore = item.gradeSetDetailsId
                }
              })
            } else {
              totalScore = totalScoreValue
            }
          }
          // 若总评成绩为百分制
          if (this.totalGradeRecordInfo.totalInputType === '1001') {
            totalScore = totalScoreValue
          }
          // 总评成绩
          currentObj.childBachelors.push({
            "score": totalScore ? totalScore.toString() : totalScore,
            "scoreValue": totalScoreValue ? totalScoreValue : totalScoreValue.toString(),
            "scoreRecordType": this.totalGradeRecordInfo.totalInputType,
            "scoreEaxmType": totalExamNature,
            "scoreType": "11001",
            "keepField": "2"
          })
          // 若存在总评成绩为空
          if (!totalScore && (totalScore !== 0 || totalScore !== '0')) {
            hasBlankTotalScore = true
          }
          // 提交发布模式
          if (operationType === '1') {
            // 若有总评成绩，则发布状态为已发布，若没有总评成绩，则发布状态为未发布
            currentObj.releaseType = totalScore ? '1' : '0'
          }
          // 总评成绩逻辑结束
        }
        // 发布重缓考
        if (this.detailInfo.condition.examType === '1' && operationType === '1') {
          // 若有成绩，则发布状态为已发布，若没有成绩，则发布状态为未发布
          currentObj.releaseType = (value.retakeScore || value.slowScore) ? '1' : '0'
          // hasBlankRetakeOrSlow = !value.retakeScore || !value.slowScore
          hasBlankRetakeOrSlow = !value.retakeScore && !value.slowScore
        }
        params.push(currentObj)
      })
      // console.log(params)
      // 提交发布模式
      if (operationType === '1') {
        // 期末总评-非允许部分发布课程，存在成绩未录入完的情况
        if (!this.admitToPartlyRelease && hasBlankTotalScore && this.detailInfo.condition.examType === '2') {
          this.$message.warning(this.$t('scoreMangementBase.cantPublish'))
          return
        }
        // 重缓考-非允许部分发布课程，存在成绩未录入完的情况
        if (!this.admitToPartlyRelease && hasBlankRetakeOrSlow && this.detailInfo.condition.examType === '1') {
          this.$message.warning(this.$t('scoreMangementBase.cantPublish'))
          return
        }
        this.$confirm(this.detailInfo.condition.courseName + '(' + this.detailInfo.condition.courseCode + ')' + this.$t('scoreMangementBase.publishConfirm'), this.$t('externamExchangeBase.prompt'), {
          confirmButtonText: this.$t('externamExchangeBase.confirm'),
          cancelButtonText: this.$t('externamExchangeBase.cancel'),
          type: 'warning'
        }).then(() => {
          scoreManagementApi.saveAndSubmitGradeEntry(params).then(res => {
            this.$message.success(this.$t('scoreMangementBase.pushlishSuccessuly'))
            this.$emit('turn-to-main-page')
          })
        })
      }
      if (operationType === '0') {
        scoreManagementApi.saveAndSubmitGradeEntry(params).then(res => {
          this.$message.success(this.$t('scoreMangementBase.savedSuccessfully'))
        })
      }
    },
    // 保存
    save() {
      this.$refs['dialogForm'].validate(valid => {
        if (valid) {
          this.saveData("0")
        }
      })
    },
    // 提交发布
    submitAndPublish() {
      this.saveData("1")
    }
  },
  beforeDestroy() {
    clearInterval(this.timer)
  }
}
</script>

<style lang="scss" scoped>
  .score-entry-table-container ::v-deep {
    .blank-title {
      margin-bottom: 15px;
      text-align: center;
      font-size: 18px;
      line-height: 35px;
    }
    .blank-sub-title {
      padding: 8px 0;
      font-size: 12px;
    }
    .select {
      width: 80px;
    }
    .input {
      width: 80px;
    }
    .el-form-item {
      // margin-bottom:  0 !important;
    }
  }

</style>